// 实现分页,能实现男女个数和总数的统计,能统计出（小于18） 和 18-45 和 45岁以上的人数
// （可以的话一条sql,分组,如果不能行就写多个sql统计）
let mysql=require("mysql");
connection=mysql.createConnection({host:"127.0.0.1",user:"root",password:"root",database:"student"});
connection.connect();
//分页
let page=1;
let pagesize=2;
let sql = "select * from user limit " + (page - 1) * pagesize + "," + pagesize;
connection.query(sql, (err, data) => {
    console.log("第"+page+"页");
    console.log(data);
});

//男女总数
connection.query("select count(*) as '男女总数' from user",(err, data)=>{
    console.log("男女总数:");
    console.log(err);
    console.log(data);
})
//女生人数
connection.query("select count(*) as '女生人数' from user where sex='女'",(err, data)=>{
    console.log("女生人数:");
    console.log(err);
    console.log(data);
})
//男生人数
connection.query("select count(*) as '男生人数' from user where sex='男'",(err, data)=>{
    console.log("女生人数:");
    console.log(err);
    console.log(data);
})
//小于18岁人数
connection.query("select count(*) as '小于18岁人数' from user where user.age<18",(err, data)=>{
    console.log("小于18岁人数:");
    console.log(err);
    console.log(data);
})
//18-45岁人数
connection.query("select count(*) as '18-45岁人数' from user where user.age>=18 and user.age<45",(err, data)=>{
    console.log("18-45岁人数:");
    console.log(err);
    console.log(data);
})
//大于45岁人数
connection.query("select count(*) as '大于45岁人数' from user where user.age>45",(err, data)=>{
    console.log("大于45岁人数:");
    console.log(err);
    console.log(data);
})
connection.end();
